import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../components/HelloWorld.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    redirect:"login",
    children:[
      {
        path: '/user/:id',
        name: 'user',
        component: () => import('../views/nav/user.vue'),
        // Redirect:"user",//设置嵌套里面的默认进入页面
      },
      {
        path: '/datas/:id',
        name: 'datas',
        component: () => import('../views/nav/datas.vue')
      },
      {
        path: '/changeData/:id',
        name: 'changeData',
        component: () => import('../views/nav/changeData.vue')
      },
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  }
]
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
export default router
